﻿Imports System.Data.OleDb
Public Class addfood
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        
    End Sub

    Protected Sub cmdaddfood_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdaddfood.Click
        Dim myGUID = Guid.NewGuid()
        Dim newFileName As String = myGUID.ToString() & ".jpg"
        Dim picLocationOnServerHardDisk = Request.MapPath("pictures") & "/" & newFileName
        picupload.SaveAs(picLocationOnServerHardDisk)
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
        Dim SqlString As String = "Insert into dishtype(dish, ingredients, preparation, pictures, dishcategory, contributor) Values (@f1,@f2,@f3,@f4,@f5,@f6)"
        ' choose dish category
        If lstcategory.SelectedIndex = 0 Then txtcategory.Text = "others"
        If lstcategory.SelectedIndex = 1 Then txtcategory.Text = "swallow"
        If lstcategory.SelectedIndex = 2 Then txtcategory.Text = "soup or stew"

        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", txtdishname.Text)
        cmd.Parameters.AddWithValue("@f2", txtingredients.Text)
        cmd.Parameters.AddWithValue("@f3", txtpreparation.Text)
        cmd.Parameters.AddWithValue("@f4", "pictures/" & newFileName)
        cmd.Parameters.AddWithValue("@f5", txtcategory.Text)
        cmd.Parameters.AddWithValue("@f6", User.Identity.Name)


        oleDbConn.Open()
        cmd.ExecuteNonQuery()

        txtdishname.Text = ""
        txtingredients.Text = ""
        txtpreparation.Text = ""
        Response.Redirect("~/confirmation.aspx")
    End Sub
End Class